package org.example;

import java.sql.*;

public class Main {
    public static void main(String[] args) {

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        Connection connection = null;
        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/clss?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&useSSL=false",
                    "root",
                    "12345678"
            );
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


        PreparedStatement ps = null;
        ResultSet rs = null;
        int num = 0;
        try {
            ps = connection.prepareStatement("select * from nobel");
            rs = ps.executeQuery();
            while (rs.next()) {
                String yr = rs.getString("yr");
                String subject = rs.getString("SUBJECT");
                String winner = rs.getString("winner");
                System.out.println(yr + "\t" + subject + "\t" + winner + "\t");
                num++;
            }
            System.out.println("数据" + num + "条");
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                connection.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    }
}